import { _decorator, animation, Component, Node } from 'cc';
import { GamerController } from './GamerController';
import { GamerBackPack } from './GamerBackpack';
const { ccclass, property } = _decorator;

@ccclass('AniBinding')
export class AniBinding extends Component {

    controller: GamerController;
    backpack: GamerBackPack;
    ani: animation.AnimationController;

    protected onEnable(): void {
        this.controller = this.node.parent?.parent?.getComponent(GamerController);
        this.backpack = this.controller?.backPack;
        this.ani = this.getComponent(animation.AnimationController);
    }

    ChooseWeapon() {
        this.backpack.ChooseWeapon();
        this.ani.setValue("IsChooseWeapon", false);
    }

    MeleeEnd() { this.ani.setValue("IsShoot", false); }

    ShootStart() { this.controller.Shoot(); }

    ReloadEnd() {
        this.controller.ReloadFinish();
        this.ani.setValue("IsReload", false);
    };

    MeleeAtk() {
        //@ts-ignore
        if (this.controller.type == "PlayerController") this.controller.MeleeAtk();
    }

    MeleeEffectStart() {
        this.controller.MeleeEffectStart();
    }

    MeleeEffectEnd() {
        this.controller.MeleeEffectEnd();
    }

    Land() {
        this.ani.setValue("IsParachuteOpen", false);
    }

    OpenP() {
        this.controller.OpenP();
    }

}